<template>
    <el-container class="home-container">
        <!-- 头部区域 -->
        <el-header>
            <div>
                <span>数据后台管理</span>
            </div>
            <el-button type="info" @click="goout">退出</el-button></el-header>
        <el-container>
            <!-- 侧边栏区域 -->
            <el-aside :width="isCollapse  ? '64px' : '200px'">
                <div class="toggle-button" @click="toggleCollapse">|||</div>
                <el-menu
                :default-active="activePath"     
                class="el-menu-vertical-demo"
                background-color="#373d41"
                text-color="#fff"
                active-text-color="#409eff"
                :collapse="isCollapse"
                :collapse-transition="false"
                router
                >
                <!-- 一级菜单 -->
                <!-- 栏目编辑  -->
                <el-submenu index="1">
                    <!-- 一级菜单编辑 -->
                    <template slot="title">
                    <i class="el-icon-edit-outline"></i>
                    <span>栏目编辑</span>
                    </template>

                    <!-- 二级菜单 -->
                    <el-menu-item :index="progrem.progremLook" @click="saveNaveState(progrem.progremLook)">
                        <i class="el-icon-menu"></i>
                       <span>栏目显示</span>
                    </el-menu-item>
                    <!-- 学院 -->
                    <el-menu-item :index="progrem.progremSchool" @click="saveNaveState(progrem.progremSchool)">
                        <i class="el-icon-menu"></i>
                       <span>学院各组织</span>
                    </el-menu-item>
                    <!-- 计算机工程系 -->
                    <el-menu-item :index="progrem.progremComputer" @click="saveNaveState(progrem.progremComputer)">
                        <i class="el-icon-menu"></i>
                       <span>计算机工程系</span>
                    </el-menu-item>
                    <!-- 经济与管理系 -->
                    <el-menu-item :index="progrem.progremEconomy" @click="saveNaveState(progrem.progremEconomy)">
                        <i class="el-icon-menu"></i>
                       <span>经济与管理系</span>
                    </el-menu-item>
                     <!-- 电子信息工程系 -->
                    <el-menu-item :index="progrem.progremElectron" @click="saveNaveState(progrem.progremElectron)">
                        <i class="el-icon-menu"></i>
                       <span>电子信息工程系</span>
                    </el-menu-item>
                     <!-- 自动化工程系 -->
                    <el-menu-item :index="progrem.progremAutomate" @click="saveNaveState(progrem.progremAutomate)">
                        <i class="el-icon-menu"></i>
                       <span>自动化工程系</span>
                    </el-menu-item>
                     <!-- 机械工程系 -->
                    <el-menu-item :index="progrem.progremMachine" @click="saveNaveState(progrem.progremMachine)">
                        <i class="el-icon-menu"></i>
                       <span>机械工程系</span>
                    </el-menu-item>
                </el-submenu>

                <!-- 部门分类 -->
                <el-submenu index="2">
                    <!-- 一级菜单编辑 -->
                    <template slot="title">
                    <i class="el-icon-office-building"></i>
                    <span>部门分类</span>
                    </template>

                    <!-- 二级菜单 -->
                    <el-menu-item :index="branch.branchEdit" @click="saveNaveState(branch.branchEdit)">
                        <i class="el-icon-menu"></i>
                       <span>导航编辑</span>
                    </el-menu-item>
                    <el-menu-item :index="branch.addBranch" @click="saveNaveState(branch.addBranch)">
                        <i class="el-icon-menu"></i>
                       <span>分类编辑</span>
                    </el-menu-item>
                </el-submenu>
                </el-menu>
            </el-aside>
            <!-- 主体区域 -->
            <el-main>
                <router-view></router-view>
            </el-main>
        </el-container>
    </el-container>
</template>

<script>
export default {
    data() {
        return {
            isCollapse: false,
            // 被激活的链接地址
            activePath: '',
            // 路由跳转地址
            progrem : {
                progremLook: '/show',
                progremSchool: '/school',
                progremComputer: '/computer',
                progremEconomy: '/economy',
                progremElectron: '/electron',
                progremAutomate: '/automate',
                progremMachine: '/machine'
            },
            branch: {
                branchEdit: '/branch/edit',
                addBranch: '/branch/addBranch'
            }
        }
    },
    created() {
        this.activePath = window.sessionStorage.getItem('activePath')
    },
    methods: {
        goout() {
            // 清除token之后跳转到登录页面
            window.localStorage.clear()
            this.$router.push('/login')
        },
        // 侧边栏折叠
        toggleCollapse() {
            this.isCollapse = !this.isCollapse
        },
        // 激活组件链接高亮
        saveNaveState(activePath) {
            window.sessionStorage.setItem('activePath', activePath)
            this.activePath = activePath
        }
    },
}
</script>

<style lang="less" scoped>
.home-container {
    height: 100%;
}
.el-header {
    background-color: #373d41;
    display: flex;
    justify-content: space-between;
    color: white;
    align-items: center;
    > div {
        display: flex;
        font-size: 20px;
        padding-left: 18px;
    }
}
.el-aside {
    background-color: #333744;
    .toggle-button {
        color: white;
        text-align: center;
        letter-spacing: 0.2em;
        font-size: 15px;
        background-color: #4a5064;
        cursor: pointer;
    }
    .el-menu {
        border-right: none;
    }
}
.el-main {
    background-color: #ecf0f5;
}
.el-menu-item {
    color: white;
}
</style>